/*
 * ControllerWizardPanel.java
 *
 * Created on Apr 3, 2011, 10:23:11 PM
 */
package carmesi.wizards;

import javax.swing.AbstractButton;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.openide.WizardDescriptor;

/**
 *
 * @author Victor
 */
public class URLControllerComponent extends CarmesiComponent implements DocumentListener{

    /** Creates new form ControllerWizardPanel */
    public URLControllerComponent(WizardDescriptor descriptor) {
        super(descriptor);
        initComponents();
        url.getDocument().addDocumentListener(this);
        viewURL.getDocument().addDocumentListener(this);
    }
    
    @Override
    public String getName() {
        return "Define Controller class";
    }
    
    public String getURLValue(){
        return url.getText();
    }
    
    public String getURLView(){
        return viewURL.getText();
    }
    
    public boolean isForwardToView(){
        return buttonForward.isSelected();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        url = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        viewURL = new javax.swing.JTextField();
        buttonRedirect = new javax.swing.JRadioButton();
        buttonForward = new javax.swing.JRadioButton();

        jLabel1.setText(org.openide.util.NbBundle.getMessage(URLControllerComponent.class, "URLControllerComponent.jLabel1.text")); // NOI18N

        url.setText(org.openide.util.NbBundle.getMessage(URLControllerComponent.class, "URLControllerComponent.url.text")); // NOI18N

        jLabel2.setText(org.openide.util.NbBundle.getMessage(URLControllerComponent.class, "URLControllerComponent.jLabel2.text")); // NOI18N

        viewURL.setText(org.openide.util.NbBundle.getMessage(URLControllerComponent.class, "URLControllerComponent.viewURL.text")); // NOI18N

        buttonGroup.add(buttonRedirect);
        buttonRedirect.setText(org.openide.util.NbBundle.getMessage(URLControllerComponent.class, "URLControllerComponent.buttonRedirect.text")); // NOI18N
        buttonRedirect.setEnabled(false);

        buttonGroup.add(buttonForward);
        buttonForward.setSelected(true);
        buttonForward.setText(org.openide.util.NbBundle.getMessage(URLControllerComponent.class, "URLControllerComponent.buttonForward.text")); // NOI18N
        buttonForward.setEnabled(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(buttonForward)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(buttonRedirect))
                    .addComponent(url, javax.swing.GroupLayout.DEFAULT_SIZE, 303, Short.MAX_VALUE)
                    .addComponent(viewURL, javax.swing.GroupLayout.DEFAULT_SIZE, 303, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(url, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(14, 14, 14)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(viewURL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(buttonForward)
                    .addComponent(buttonRedirect))
                .addContainerGap(17, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton buttonForward;
    private javax.swing.ButtonGroup buttonGroup;
    private javax.swing.JRadioButton buttonRedirect;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField url;
    private javax.swing.JTextField viewURL;
    // End of variables declaration//GEN-END:variables

    @Override
    public void insertUpdate(DocumentEvent e) {
        verificarValores();
        fireChangeEvent();
    }

    @Override
    public void removeUpdate(DocumentEvent e) {
        verificarValores();
        fireChangeEvent();
    }

    @Override
    public void changedUpdate(DocumentEvent e) {
        verificarValores();
        fireChangeEvent();
    }
    
    public void verificarValores(){
        boolean viewURLEnabled;
        if(viewURL.getText().trim().equals("")){
            viewURLEnabled=false;
        }else{
            viewURLEnabled=true;
        }
        buttonForward.setEnabled(viewURLEnabled);
        buttonRedirect.setEnabled(viewURLEnabled);
    }

}
